package popoer.price.thief.web.servlet;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import popoer.price.thief.domain.Product;
import popoer.price.thief.service.Thief;
import popoer.price.thief.service.ThiefFactory;

@SuppressWarnings("serial")
public class ProductServlet extends HttpServlet {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ProductServlet.class.getName());

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String type = req.getParameter("type");
		String link = req.getParameter("link");
		if (logger.isLoggable(Level.FINE)) {
			logger.fine("HttpServletRequest, HttpServletResponse - String link=" + link); //$NON-NLS-1$			
		}
		resp.setContentType("text/html;charset=utf-8");
		
		Thief thief = ThiefFactory.getTheif(type);
		try {
			List<Product> products = thief.getProducts(link);
			req.setAttribute("products", products);
			req.getRequestDispatcher("/product.jsp").include(req, resp);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
